<template>
  <div class='app-container '>
      
      <a-table
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            :columns="attachColumns"
            :data-source="fileList"
            bordered
            :pagination="showPage?pagination: showPage"
             @change="pageChange"
            rowKey="id"
          >
            <template slot="fileName" slot-scope="text, record">
              <span v-if="previewDisabled">{{ record.fileName }}</span>      
              <a-button v-else type="link"  @click="showAttach(record)">{{ record.fileName }}</a-button>
          </template>
           <template slot="size" slot-scope="text, record">
              <span  >{{ record.fileName }}</span>
          </template>
    </a-table>
  </div>
</template>

<script>


import { uploaderMixin } from '../common/mixins'
import { formatSize } from '../common/utils'
const attachColumns = [
{
    title: '附件名称',
    dataIndex: 'fileName',
    scopedSlots: { customRender: 'fileName' },
},
{
    title: '附件大小',
    dataIndex: 'size',
    width: '15%',
    customRender:function (text) {
          return formatSize(text)
        }
},
{
    title: '上传时间',
    dataIndex: 'uploadTime',
    width: '20%',
},
{
    title: '上传者',
    dataIndex: 'uploaderName',
    width: '20%',
},
]
export default {
  name: 'uploadedFile',
  mixins:[uploaderMixin],
  components: {
  },
  props:{
     previewDisabled:{
       type:Boolean,
       default:false
     },
     
  },
  data() {
    return {
        selectedRowKeys:[],
        selectionRows: [],
        attachColumns,
        pagination: {
        current: 1,
        pageSize: 30,
        pageSizeOptions: ['30', '50', '100'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        total: 0,
        showQuickJumper: true,
        showSizeChanger: true,
      },
    };
  },
  created(){
  },
  computed: {
      fileList () {
        let vm = this
        this.pagination.current = 0
        this.pagination.total = this.uploader.fileListDefault.length
        return this.uploader.fileListDefault
      },
      showPage(){
        let vm = this
       
        return this.uploader.showPage
      }
    },
  methods: {
     pageChange(page) {
      
      this.pagination.current = page.current
      // this.queryByChangeProjectBuildId()
    },
    showAttach(record){
      this.uploader.handlePreview(record)
    },
     onSelectChange(selectedRowKeys, selectionRows) {
            this.selectedRowKeys = selectedRowKeys;
            this.selectionRows = selectionRows;
        },
         onClearSelected() {
            this.selectedRowKeys = [];
            this.selectionRows = [];
        },
  },
 
   
  filters: {
  },
  watch:{
  },
  mounted(){

  }
 }
</script>

<style lang="less" scoped>

@import '../assets/common.less';
</style>
